{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "965ef715",
   "metadata": {},
   "source": [
    "* 2022/09/13\n",
    "* 课堂笔记"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8fd3cf48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 上周回顾（range()) :range:范围\n",
    "## 创建自然数\n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8cb2233d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "## for + range 决定循环的次数\n",
    "for i in range(5):\n",
    "    print(i)\n",
    "# 循环5次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c07a2449",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bfb3ca7f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# 产生5-1=4个数，1开始，5结束\n",
    "for i in range(1,5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "51d8fb40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "307dfcc8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "# 在1-10之间产生数值，每个3个数产生一个数值，数值范围是1-10\n",
    "for i in range(1,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3117d41",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "> 1. 数值\n",
    ">> 1. int\n",
    ">> 2. float\n",
    ">> 3. complex\n",
    "\n",
    "> 2. 字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5ba9336b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "## Number（数值） int\n",
    "\n",
    "a = 9 \n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "62bbac0d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.5 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "# float\n",
    "b = 11.5\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7fb09b94",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "## complex(虚数，复数)\n",
    "c = 5 + 3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7dbfa995",
   "metadata": {},
   "source": [
    "## 字符串(string)\n",
    "### 1.关于字符串的基本内容\n",
    "### 2.关于字符串的方法及函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8e470609",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "# 字符串要加引号\n",
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "de31176d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8e6698fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "59994e73",
   "metadata": {},
   "source": [
    "## 2.2关于字符串的方法和函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "16807a30",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化温泉镇\n"
     ]
    }
   ],
   "source": [
    "# 关于有序性\n",
    "title = \"广州南方学院坐落于广州市从化温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "2377091e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取单一值\n",
    "title[0]  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "652da5a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'落'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "f00455eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "c3c62f39",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#检查文本的总长度\n",
    "len(title) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "ff703027",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 倒数第一个字\n",
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "606ddd4f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'市'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 倒数第六个字\n",
    "title[-6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "b292abf6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取一定范围的值，这钟方法我们称之为--切片\n",
    "title[0:5] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "09691d2a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院坐'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "c00ae5a8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院坐落于'"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:9]\n",
    "# 0可以省略不取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "eabf5e84",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 以上0123这类一个数字代表一个字 称之为“index”索引值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "bd66a26e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 温\n",
      "15 泉\n",
      "16 镇\n"
     ]
    }
   ],
   "source": [
    "#  利用for循环 遍历文本信息\n",
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "d2a529b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在\n"
     ]
    }
   ],
   "source": [
    "# 如何判断一段文本中是否存在广州，例如文本 title 中的内容\n",
    "# 可以利用if else判断田间来进行判断\n",
    "if \"广州\" in title:\n",
    "    print(\"在\")\n",
    "\n",
    "else:\n",
    "    print(\"不在\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "8f2e3b7c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州这个词在这段文字中\n",
      "广州这个词在这段文字中\n"
     ]
    }
   ],
   "source": [
    "# enumerate枚举，既可以获取到内容，又可以获取到索引值\n",
    "for i,j in enumerate(title):\n",
    "    if j == \"广\":\n",
    "        if title[i+1] == \"州\":\n",
    "            print(\"广州这个词在这段文字中\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a777664",
   "metadata": {},
   "source": [
    "## in 检查成员对象\n",
    "#### 1.字符串不能用来运算！需区分数字（int）与字符串（str）\n",
    "#### 2.str.capitalize():可以将首字母转为大写\n",
    "#### 3.str.count():数量？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "1e4b9078",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\" in title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "896739ff",
   "metadata": {},
   "source": [
    "## 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d641686b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好,Alex\n"
     ]
    }
   ],
   "source": [
    "print('你好'+','+'Alex')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "02e7644d",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"Marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "f1c39020",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "03e18646",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")\n",
    "# r 这个字母有几个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "82b1c940",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院坐落于广州市从化温泉镇'"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "11cd6402",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"广\")\n",
    "# 广 这个字有几个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "a05eb8e1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"啊\")\n",
    "# 啊 这个字有几个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "54399530",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州南方学院', '广州市从化温泉镇']"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"坐落于\")\n",
    "# 以坐落于为分界将这句话分成两部分"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
